﻿Chenxin.UI.AuthorityPostionMgr = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/AuthorityPostionManage.ashx',
    createGrid: function() {
        return new Chenxin.UI.Pagination({
            actionUrl: this.actionUrl + '?op=getlist',
			renderTo:'setting_table'
        });
    },
    initEvent: function() {
        var _this = this;
		$('#btn_add').click(function(){
			_this.add();
			_this.form.setTitle('添加设定');
		});
		$('#btn_del').click(function(){
			_this.del();
		});
		
		
		$('.tr_settinglist').live('click',function(){	
			$('.tr_settinglist,.selected_orgbgcolor').each(function(){
				$(this).removeClass('selected_orgbgcolor');	
			});
			
			$(this).toggleClass('selected_orgbgcolor');	
			_this.currentId=this.id;
		});
		$('.tr_settinglist').live('mouseover',function(){
			$(this).toggleClass('orgbgcolor');
		});
		$('.tr_settinglist').live('mouseout',function(){
			$(this).toggleClass('orgbgcolor');
		});
    },

	createForm:function(){
		return new Chenxin.UI.AuthorityPostionForm({
			scope:this,
			saveSucc:function(data,msg){
				this.grid.reload();	
			}
		});
	},
    createSearch: function() {
        return new Chenxin.UI.AuthorityPostionSearch({
            scope: this
        });
    },
    initComponent: function() {
        Chenxin.UI.AuthorityPostionMgr.superclass.initComponent.call(this);
    }
});

/**
*@description 设置表单
*/
Chenxin.UI.AuthorityPostionForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/AuthorityPostionManage.ashx',
    renderTo: 'jqm_authoritypostion',
    id: 'authoritypostion',
    jqmWidth: 600,
    customerFormVal: function(model) {
        if (!model.OfficeNameList) {
            alert('请勾选职务！');
            return false;
        }
        return true;
    },
    afterGetFormJson: function(model) {
        Chenxin.apply(this.form.additionalParam, model);
    },
    createComboList: function() {
        var _this = this;
        var authority = new Chenxin.UI.Combo({
            containerId: '#' + this.id + '_Authority',
            tbxWidth: 120,
            name: 'postname',
            inModelType: 'txt',
			required:true,
            items: comboCommon.authority
        });


        //城市
        var city = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#' + this.id + '_City',
            name: 'cityid',
            tbxWidth: 120,
            inModelType: 'none',
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    company.clearItems();
                } else {
                    company.param.fatherid = this.getValue();
                    company.reload();
                }
            }
        });

        //公司
        var company = new Chenxin.UI.StructCombo({
            autoLoad: false,
            param: { op: 'getcompany' },
            name: 'companyid',
            containerId: '#' + this.id + '_Company',
            tbxWidth: 120,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    _this.loadPostion();
                } else {
                    _this.loadPostion(this.getValue());
                }
            }
        });
        return [city, company, authority];
    },
    loadPostion: function(companyid) {
        if (companyid) {
            Chenxin.ajax({
                url: this.actionUrl + '?op=getofficename',
                type: 'get',
                dataType: 'json',
                data: { companyid: companyid },
                onSuccess: function(data, msg) {
                    var html = '';
                    for (var i = 0; i < data.items.length; i++) {
                        html += '<div class="fl" style="width:100px;"><input type="checkbox" name="OfficeNameList" value="' + data.items[i] + '" />' + data.items[i]+"</div>";
                    }
					$('#tr_postion').empty();
                    $('#tr_postion').append(html);
                }
            });
        } else {
            $('#tr_postion').text('请选择公司!');
        }
    },
    createForm: function() {
        return Chenxin.FormCommon.AuthorityPostionForm(this.id);
    },
    initEvent: function() {
        var _this = this;
        $('#' + this.id + '_Save').live('click', function() {
            _this.save();
        });
        $('#' + this.id + '_Cancle').live('click', function() {
            _this.hide();
        });
    },
    initComponent: function() {
        Chenxin.UI.AuthorityPostionForm.superclass.initComponent.call(this);
    }
});

/**
*@description 查询面板
*/
Chenxin.UI.AuthorityPostionSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id:'aps_search',
	initEvent:function(){		
		var _this=this;
		$('#btn_search').click(function(){
			if(_this.scope.reloadGrid){
				_this.scope.reloadGrid();				
			}
		})
	},
	createComboList:function(){
	
		var authority = new Chenxin.UI.Combo({
            containerId: '#aps_SearchAuthority',
            tbxWidth: 120,
			name:'postname',
            inModelType: 'txt',
			items:comboCommon.authority
        });
		
		
		//城市
		var city=new Chenxin.UI.StructCombo({
			param:{op:'getcity'},
			containerId:'#aps_SearchCity',
			name:'cityid',
			tbxWidth:120,
			onSelected:function(){
				if(this.getValue()==this.defVal){
					company.clearItems();
				}else{
					company.param.fatherid=this.getValue();
					company.reload();				
				}
			}
		});
		
		//公司
		var company=new Chenxin.UI.StructCombo({
			autoLoad:false,
			param:{op:'getcompany'},
			name:'companyid',
			containerId:'#aps_SearchCompany',
			tbxWidth:120
		});
		
		
		return [city,company,authority];
	},
	initComponent:function(){
		Chenxin.UI.AuthorityPostionSearch.superclass.initComponent.call(this);
	}
});

Chenxin.FormCommon.AuthorityPostionForm=function(comboIdPrefix){
	return '<table class="tbl_f"><tbody><tr><th style="width:60px;">城市：</th><td><div id="'+comboIdPrefix+'_City" style="z-index:904; margin-right: 5px;" class="SelectWrapSingle"></td></tr><tr><th><span class="isfilled">*</span>公司：</th><td><div id="'+comboIdPrefix+'_Company" style="z-index:903; margin-right: 5px;" class="SelectWrapSingle"></td></tr><tr><th><span class="isfilled">*</span>职权：</th><td><div id="'+comboIdPrefix+'_Authority" style="z-index:902; margin-right: 5px;" class="SelectWrapSingle"></td></tr><tr><th><span class="isfilled">*</span>职务：</th><td id="tr_postion">请选择公司!</td></tr><tr><td colspan="2" align="right"><div style="float:right; margin-right:15px;"><a id="' + comboIdPrefix + '_Save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + comboIdPrefix + '_Cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></tbody></table>';
},

$(document).ready(function(){
	var authorityPostionMgr=new Chenxin.UI.AuthorityPostionMgr();
});